//
//  JSTInterestcircleContentView.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/11.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTInterestcircleContentView.h"
#import "JSTInterestcircleContentFrame.h"
#import "JSTInterestcircleDataModel.h"

@implementation JSTInterestcircleContentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // 昵称
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.font = kSystemFont(kCurrentScreenWidth(12));
        nameLabel.textColor=[UIColor colorWithHexString:@"000000"];
        [self addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        // 正文
        MLEmojiLabel *textLabel = [[MLEmojiLabel alloc] init];
        [self addSubview:textLabel];
        self.contentLabel = textLabel;
        
        // 头像
        JSTImageView *iconImg = [[JSTImageView alloc] init];
        iconImg.layer.borderColor=kANGSeparateLineColor.CGColor;
        [self addSubview:iconImg];
        self.iconImg = iconImg;
    }
    return self;
}

- (void)setContentFrame:(JSTInterestcircleContentFrame *)contentFrame
{
    _contentFrame = contentFrame;
    self.frame = contentFrame.frame;
    
    // 取出网络数据
    JSTInterestcircleDataModel *model = contentFrame.model;
    
    // 昵称
    self.nameLabel.text = model.userName;
    self.nameLabel.frame = contentFrame.nameFrame;
    
    // 正文
    self.contentLabel.font = kSystemFont(kCurrentScreenWidth(10));
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.textInsets = UIEdgeInsetsMake(5, 0, 0, 0);
    self.contentLabel.textColor= [UIColor colorWithHexString:@"595757"];
    self.contentLabel.emojiDelegate = self;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.contentLabel.isNeedAtAndPoundSign = YES;
    self.contentLabel.disableThreeCommon=YES;
    // _contentLabel.customEmojiRegex =@"[\\[e_]+[0-9]{1,4}+[\\]]";
    self.contentLabel.customEmojiRegex = @"\\[[a-zA-Z0-9\\u4e00-\\u9fa5]+\\]";
    self.contentLabel.customEmojiPlistName = @"Emoji_icon.plist";
    [self.contentLabel setEmojiText:model.contentText];
    self.contentLabel.frame = contentFrame.textFrame;
    [self.contentLabel sizeToFit];
    
    // 头像
    self.iconImg.frame = contentFrame.iconFrame;
    [self.iconImg setImageWithURL:[NSURL URLWithString:model.iconImgUrl] placeholderImage:[UIImage imageNamed:@"healthy_head"]];
    self.iconImg.layer.masksToBounds = YES;
    self.iconImg.layer.cornerRadius = self.iconImg.width/2;
    
}
@end
